package com.water.controller;

import com.water.entity.RdChangemaxvalue;
import com.water.service.RdChangemaxvalueService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.*;

/**
 * (RdChangemaxvalue)表控制层
 *
 * @author 小博
 * @since 2020-12-15 10:03:36
 */
@Controller
@RequestMapping("rdchang")
public class RdChangemaxvalueController {
    /**
     * 服务对象
     */
    @Resource
    private RdChangemaxvalueService rdChangemaxvalueService;


    /**
     * 跳转到最大底码修正记录
     * @return
     */
    @RequestMapping("/rd_reportMaxValue")
    public String rd_reportMaxValue(){
        return "./rd/rd_reportMaxValue";
    }

    /**
     *通过操作员查询多条数据
     * @return 影响行数
     */
    @GetMapping("selectRdChangemaxValue")
    public ModelAndView selectRdChangeValue(ModelAndView model){
        List<Map<String,Object>> mapList = rdChangemaxvalueService.selectRdChangeMaxValue();
        Set<Object> set = new HashSet<>();
        for (int i = 0;i < mapList.size();i++){
            if(!set.contains(mapList.get(i).get("EmpName"))){
                set.add(mapList.get(i).get("EmpName"));
            }
        }
        List<String> list = new ArrayList<>();
        Iterator<Object> it = set.iterator();
        while (it.hasNext()){
            list.add((String) it.next());
        }
        for(int i = 0;i < list.size();i++){
            mapList.get(i).put("manager",list.get(i));
        }
        Iterator<Map.Entry<String,Object>> its = mapList.get(0).entrySet().iterator();
        while (its.hasNext()){
            Map.Entry<String,Object> map = its.next();
            System.out.println("key="+map.getKey()+",value="+map.getValue());
        }
        model.addObject("mapList",mapList);
        model.setViewName("../rd/rd_reportCPreAmount");
        return model;
    }

    /**
     *通过操作员查询多条数据
     *@return 影响行数
     */
    @GetMapping("EmpselectRdChangemaxValue/{str}")
    public ModelAndView EmpselectRdChangeValue(@PathVariable("str") String str, ModelAndView model){
        List<Map<String,Object>> mapList = rdChangemaxvalueService.selectEmpRdChangeMaxValue();
        List<Map<String,Object>> list = rdChangemaxvalueService.selectRdChangeMaxValue();
        Set<Object> set = new HashSet<>();
        for (int i = 0;i < mapList.size();i++){
            if(!set.contains(mapList.get(i).get("EmpName"))){
                set.add(list.get(i).get("EmpName"));
            }
        }
        List<String> arr = new ArrayList<>();
        Iterator<Object> it = set.iterator();
        while (it.hasNext()){
            arr.add((String) it.next());
        }
        if(mapList.size() < arr.size()){
            for(int i = 0;i < arr.size();i++){
                if(i >= mapList.size()){
                    Map<String,Object> map = new HashMap<>();
                    map.put("manager",arr.get(i));
                    mapList.add(map);
                }else{
                    mapList.get(i).put("manager",list.get(i));
                }
            }
        }else{
            for(int i = 0;i < arr.size();i++){
                mapList.get(i).put("manager",list.get(i));
            }
        }
        Iterator<Map.Entry<String,Object>> its = mapList.get(0).entrySet().iterator();
        while (its.hasNext()){
            Map.Entry<String,Object> map = its.next();
            System.out.println("key="+map.getKey()+",value="+map.getValue());
        }
        model.addObject("mapList",mapList);
        model.setViewName("rd/rd_reportCPreAmount");
        return model;
    }

}